package org.styx.account.rest;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.styx.account.domain.Account;
import org.styx.account.service.AccountService;
import org.styx.common.response.R;
import org.styx.common.response.ResultCode;

import java.math.BigDecimal;

/**
 * @date 2021/8/6
 * @auther uranus
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/account")
public class AccountController {

    private final AccountService accountService;

    /**
     * 测试
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public R<Account> get(@PathVariable("id") Long id){
        return R.data(accountService.get(id));
    }

    /**
     * 扣减账户余额
     * @param userId
     * @param money
     * @return
     */
    @RequestMapping("/decrease")
    public R decrease(@RequestParam("userId")Long userId, @RequestParam(
            "money")BigDecimal money){
        accountService.decrease(userId,money);
        return R.success(ResultCode.SUCCESS,"扣减账户余额成功");
    }

}
